﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Manzana;
using System.IO;
using System.Globalization;

namespace IVR3Downloader.Class
{
    public class Movie
    {
        private static string[] SIZES = { "B", "KB", "MB", "GB", "TB" };

        public string FilePath { get; set; }
        public ulong FileSize { get; set; }
        public bool IsChecked { get; set; }

        public String FileName
        {
            get
            {
                return Path.GetFileName(this.FilePath);
            }
        }

        public String UserSize
        {
            get
            {
                return ProgressionDownload.CalculateUserSize(this.FileSize);
            }
        }

        public DateTime DateCreated
        {
            get
            {
                return this.CreationDate();
            }
        }

        /*private String CalculateUserSize()
        {
            int counter = 0;
            double result = this.FileSize;

            do
            {
                if (result < 1024 || counter >= 4)
                {
                    break;
                }

                result = result / 1024;
                counter++;
            }
            while (true);

            return String.Format("{0:0.00} {1}", result, SIZES[counter]);
        }*/

        private DateTime CreationDate()
        {
            try
            {
                String dateTime = Path.GetFileNameWithoutExtension(this.FileName.Substring(4));

                DateTime creationDateTime = DateTime.ParseExact(dateTime, "yyyy-MM-dd HH-mm-ss", new CultureInfo("en-US"));

                return creationDateTime;
            }
            catch (Exception)
            {
                return DateTime.Parse("1/1/1900");
            }
        }

    }
}
